package com.ryan.route.controller;


import com.ryan.route.entity.RouteComment;
import com.ryan.route.service.RouteCommentService;
import com.ryan.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 评论 前端控制器
 * </p>
 *
 * @author ryan
 * @since 2020-08-03
 */
@RestController
@RequestMapping("/route/comment")
public class RouteCommentController {

    @Autowired
    private RouteCommentService commentService;

    /**
     * 通过路线ID获取路线评论列表
     * @param pageIndex
     * @param pageSize
     * @param routeId
     * @return
     */
    @GetMapping("GetCommentList/{pageIndex}/{pageSize}")
    public R GetCommentList(@PathVariable long pageIndex,
                            @PathVariable long pageSize,
                            @RequestParam String routeId){
        Map<String, Object> map = commentService.GetCommentList(pageIndex,pageSize,routeId);
        return R.ok().data(map);
    }

    /**
     * 添加评论
     * @param comment
     * @return
     */
    @PostMapping("/addComment")
    public R addComment(@RequestBody RouteComment comment){
        boolean save = commentService.save(comment);
        return save?R.ok():R.error();
    }

}

